package com.itnoob.whitelist.config;

import com.itnoob.whitelist.annotation.WhiteList;
import com.itnoob.whitelist.aspect.WhiteListAspect;
import com.itnoob.whitelist.service.WhiteListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhoujun
 * @date 2025/3/20 23:59
 */
@Configuration
@EnableConfigurationProperties(WhiteListProperties.class)
@ConditionalOnProperty(prefix = "whitelist",name = "enabled",havingValue = "true")
public class WhiteListAutoConfiguration
{
    //注入白名单属性
    @Autowired
    private WhiteListProperties whiteListProperties;

    //注入白名单服务
    @Autowired
    private WhiteListService whiteListService;

    /**
     * 注册白名单切面
     * @return
     */
    @Bean
    public WhiteListAspect whiteListAspect(){
        return  new WhiteListAspect(whiteListProperties,whiteListService);
    }

}
